<%#
 Copyright 2013-2018 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
version: '2'
services:
<%_ if (enableRancherLoadBalancing && hasFrontApp) { _%>
    lb:
      image: rancher/load-balancer-service
      ports:
        # Listen on public port 80 and direct traffic to private port 8080 of the service
        - 80:<%= frontAppPort %>
      links:
        # Target services in the same stack will be listed as a link
        - <%= frontAppName %>:<%= frontAppName %>
<%_ } _%>
<%_ for(var i = 0; i < appConfigs.length; i++) { _%>
<%- appsYaml[i] %>
<%_ } _%>
<%_ if (useKafka) { _%>
    zookeeper:
        image: <%= DOCKER_ZOOKEEPER %>
    kafka:
        image: <%= DOCKER_KAFKA %>
        environment:
            KAFKA_ADVERTISED_HOST_NAME: kafka
            KAFKA_ADVERTISED_PORT: 9092
            KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
            KAFKA_CREATE_TOPICS: "topic-jhipster:1:1"
        #ports:
        #    - 9092:9092  # Uncomment to make Kafka available externally
<%_ } _%>
<%_ if (serviceDiscoveryType === 'eureka') { _%>
    jhipster-registry:
        image: <%= DOCKER_JHIPSTER_REGISTRY %>
        #volumes:
        #    - ./central-server-config:/central-config
        environment:
            - SPRING_PROFILES_ACTIVE=dev<% if (authenticationType === 'oauth2') { %>,oauth2<% } %><% if (authenticationType === 'uaa') { %>,uaa<% } %>
            - SPRING_SECURITY_USER_PASSWORD=<%= adminPassword %>
            <%_ if (monitoring === 'elk') { _%>
            - JHIPSTER_LOGGING_LOGSTASH_ENABLED=true
            - JHIPSTER_LOGGING_LOGSTASH_HOST=jhipster-logstash
            - JHIPSTER_METRICS_LOGS_ENABLED=true
            - JHIPSTER_METRICS_LOGS_REPORTFREQUENCY=60
            <%_ } _%>
            <%_ if (monitoring === 'prometheus') { _%>
            - JHIPSTER_METRICS_PROMETHEUS_ENABLED=true
            - JHIPSTER_METRICS_PROMETHEUS_ENDPOINT=/prometheusMetrics
            <%_ } _%>
            - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
            - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./config/
            # Uncomment to use a Git configuration source instead of the local filesystem
            # mounted from the registry-config-sidekick volume
            # - GIT_URI=https://github.com/jhipster/jhipster-registry/
            # - GIT_SEARCH_PATHS=central-config
        ports:
            - 8761:8761
        volumes:
          - /config
        volumes_from:
          - registry-config-sidekick
        labels:
          io.rancher.sidekicks: registry-config-sidekick
<%_ } _%>
<%_ if (serviceDiscoveryType === 'consul') { _%>
    consul:
        image: <%= DOCKER_CONSUL %>
        ports:
            - 8300:8300
            - 8500:8500
            - 8600:8600
        command: consul agent -dev -ui -client 0.0.0.0
    consul-config-loader:
        image: <%= DOCKER_CONSUL_CONFIG_LOADER %>
        environment:
            - INIT_SLEEP_SECONDS=5
            - CONSUL_URL=consul
            - CONSUL_PORT=8500
        volumes:
          - /config
        volumes_from:
          - registry-config-sidekick
        labels:
          io.rancher.sidekicks: registry-config-sidekick
<%_ } _%>
<%_ if (serviceDiscoveryType === 'eureka' || serviceDiscoveryType === 'consul') { _%>
    registry-config-sidekick:
        # this docker image must be built with:
        # docker build -t <%= dockerRepositoryName %><% if (dockerRepositoryName !== '') { %>/<% } %>registry-config-sidekick registry-config-sidekick
        image: <%= dockerRepositoryName %><% if (dockerRepositoryName !== '') { %>/<% } %>registry-config-sidekick
        tty: true
        stdin_open: true
        command:
          - cat
        volumes:
          - config:/config
<%_ } _%>
<%_ if (monitoring === 'elk') { _%>
    jhipster-elasticsearch:
        image: <%= DOCKER_JHIPSTER_ELASTICSEARCH %>
        ports:
            - 9200:9200
            - 9300:9300
        # Uncomment this section to have elasticsearch data persisted to a volume
        #volumes:
        #   - ./log-data:/usr/share/elasticsearch/data
    jhipster-logstash:
        image: <%= DOCKER_JHIPSTER_LOGSTASH %>
        command: logstash -f /conf/logstash.conf
        ports:
            - 5000:5000/udp
        # Uncomment this section to have logstash config loaded from a volume
        #volumes:
        #    - ./log-conf/:/conf
    jhipster-console:
        image: <%= DOCKER_JHIPSTER_CONSOLE %>
        ports:
            - 5601:5601
    <%_ if (deploymentApplicationType === 'microservice') { _%>
    # Uncomment this section to enable Zipkin
    #jhipster-zipkin:
    #    image: <%= DOCKER_JHIPSTER_ZIPKIN %>
    #    ports:
    #        - 9411:9411
    #    environment:
    #        - ES_HOSTS=http://jhipster-elasticsearch:9200
    #        - ZIPKIN_UI_LOGS_URL=http://localhost:5601/app/kibana#/dashboard/logs-dashboard?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-1h,mode:quick,to:now))&_a=(filters:!(),options:(darkTheme:!f),panels:!((col:1,id:logs-levels,panelIndex:2,row:1,size_x:6,size_y:3,type:visualization),(col:7,columns:!(stack_trace),id:Stacktraces,panelIndex:7,row:1,size_x:4,size_y:3,sort:!('@timestamp',desc),type:search),(col:11,id:Log-forwarding-instructions,panelIndex:8,row:1,size_x:2,size_y:3,type:visualization),(col:1,columns:!(app_name,level,message),id:All-logs,panelIndex:9,row:4,size_x:12,size_y:7,sort:!('@timestamp',asc),type:search)),query:(query_string:(analyze_wildcard:!t,query:'{traceId}')),title:logs-dashboard,uiState:())
    <%_ } _%>
<%_ } _%>
